<?php


namespace app\common\his_info;

use think\Model;
use think\Db;


class His_comm extends Model
{

    /**
     * 通过用户ID读取分院信息.
     */
    public function get_hospital_userid($user_id)
    {
        $sqlstr="select a.hospital_id as address_id,hospital_name,address,tel_user,tel,city_name,province,city,district,twon from tp_hospital a,tp_hospital_user b where a.hospital_id=b.hospital_id and a.parent_hospital_id=b.parent_hospital_id and b.zxbz=0 and user_id=$user_id";
        $hospital_list=Db::query($sqlstr);
        return $hospital_list;
    }
    public function get_hospital_admin($user_id)
    {
        $sqlstr="select  a.hospital_id as address_id,hospital_name,address,tel_user,tel,city_name,province,city,district,twon from tp_hospital a,tp_hospital_user b where a.hospital_id=b.hospital_id and a.parent_hospital_id=b.parent_hospital_id and b.zxbz=0 and user_id=$user_id";
        $hospital_list=Db::query($sqlstr);
        return $hospital_list;
    }

    public function phpreadExcel(){
        vendor('PHPExcel.PHPExcel');
        $objPHPExcel = new \PHPExcel();
        $file = request()->file('excel');
        // var_dump($file);exit;
        $info = $file->validate(['size'=>9956789,'ext'=>'xlsx,xls,csv'])->move('./public/upload/excel');  
        if($info){  
            $exclePath = $info->getSaveName();  //获取文件名  
            $file_name = './public/upload/excel/' . $exclePath;   //上传文件的地址  
            $objReader =\PHPExcel_IOFactory::createReader('Excel2007');  
            $obj_PHPExcel =$objReader->load($file_name, $encode = 'utf-8');  //加载文件内容,编码utf-8  
            echo "<pre>";  
            $excel_array=$obj_PHPExcel->getsheet(0)->toArray();   //转换为数组格式  
            array_shift($excel_array);  //删除第一个数组(标题); 
            $data['file_path'] = $file_name;
            $data['excel_array'] = $excel_array;
            return $data;
        }
    }
}